mootools
Comment previewing is an awesome addition to any blog. I've seen really simple comment previewing and some really complex comment previewing. The following is a tutorial on creating very basic comment previewing using MooTools.
评论预览是对任何博客的补充。 我看过非常简单的评论预览和一些非常复杂的评论预览。 以下是有关使用MooTools创建非常基本的注释预览的教程。
XHTML (The XHTML)
Your Name:
Your Email: Your Website: Your Comment:
You can set up your XHTML any way you'd like. It's important for the sake of consistency to make your preview display look as closely as possible to your real comments display.
您可以根据需要设置XHTML。 为了保持一致性,重要的是使预览显示与实际评论显示尽可能接近。
CSS (The CSS)
.lp-block { width:400px; float:left; }.lp-block input, .lp-block textarea { width:90%; }#live-preview-display { background:#eee; padding:10px; margin-left:50px; margin-top:20px; }#lp-name { font-weight:bold; }#lp-avatar { float:right; margin:0 0 20px 20px; }#lp-comment { padding-top:10px; font-style:italic; line-height:19px; }
Make your "preview" CSS look just like your real comments display.
使您的“预览” CSS看起来就像您的实际注释显示一样。
MooTools JavaScript (The MooTools JavaScript)
(function($){ window.addEvent('domready',function(){ //the build process var build = function() { //vars (fields) and blocks var lpcomment = $('lp-comment'), lpname = $('lp-name'), lpavatar = $('lp-avatar'); var name = $('name'), email = $('email'), website = $('website'), comment = $('comment'); //comment lpcomment.set('text',comment.value); lpcomment.set('html',lpcomment.get('html').replace(/\n/g,'')); //name & websites if(website.value && (website.value).test(/http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/)) { lpname.set('html','' + name.value + ' says:'); } else { lpname.set('text',name.value + ' says:'); } //gravatar if(email.value && (email.value).test(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) { var md5Email = MD5(email.value); lpavatar.set('html',''); } }; //comment...easy $$('#live-preview-form input, #live-preview-form textarea').addEvents({ keyup: build, blur: build }); });})(document.id);
The JavaScript is quite easy. Note that I'm doing very basic validation and formatting -- you may get as fancy or simple as you'd like. Also note that I'm using an MD5 function for the gravatar functionality. The MD5 function was .
JavaScript非常简单。 请注意,我正在做非常基本的验证和格式化-您可能会喜欢上自己想像的或简单的。 另请注意,我使用的是MD5功能的Gravatar功能。 在 MD5功能。
This is as basic as it gets. You may want to implement functionality that checks for valid URLs and email addresses. You may also want to implement a regular expression that turns two line breaks into </p><p> tags. If you'd like to implement a more sophisticated system, I highly recommend using Thomas Aylott's .
这是最基本的。 您可能想要实现检查有效URL和电子邮件地址的功能。 您可能还想实现一个将两个换行符转换为</ p> <p>标记的正则表达式。 如果您想实现一个更复杂的系统,我强烈建议您使用Thomas Aylott的 。
翻译自:
mootools